/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;
import Model.*;
import javax.microedition.lcdui.*;

/**
 *
 * @author Pisarchik_S
 */
public class CreateNewCategory implements CommandListener
{
    Dispatcher m_Dispatcher;
    CModel m_Model;

    public CreateNewCategory(Dispatcher dispatcher, CModel model)
    {
        m_Dispatcher = dispatcher;
        m_Model = model;
    }

    Command m_CancelCommand = new Command("Скасаваць", Command.CANCEL, 0);
    Command m_OkCommand = new Command("Стварыць катэгорыю", Command.OK, 0);

    TextField m_CategoryItem;

    public void Init()
    {
        Form form = new Form("Стварыць катэгорыю");
        m_CategoryItem = new TextField("Назва ", "", 12, TextField.PLAIN);

        form.append(m_CategoryItem);
        form.addCommand(m_CancelCommand);
        form.addCommand(m_OkCommand);
        form.setCommandListener(this);

        m_Dispatcher.GetDisplay().setCurrent(form);
    }

    public void commandAction(Command c, Displayable s)
    {
        if (c == m_CancelCommand)
        {
            m_Dispatcher.GetShowCategories().Init();
        }
        if (c == m_OkCommand)
        {
            m_Model.AddCategory(new CCategory(m_CategoryItem.getString()));
            m_Dispatcher.GetShowCategories().Init();
        }
    }


}
